(function(){

/**
 * Created by sallyshen on 15/6/9.
 */
'use strict';

angular.module('controllers.faultLocation.sysBusinessCount')
  .controller('byTimeController',byTimeController)
  .controller('byProvinceController',byProvinceController)
  .controller('successRateController',successRateController)
  .controller('thirtyController',thirtyController);

function byTimeController($scope,sysBusCountData,sysBusCountOption,sysBusCountServer){
  $scope.shoumun = {flag : 1};
  $scope.selector = sysBusCountData.selector;
  $scope.sendData = sysBusCountData.sendData;

  var byTimechart = echarts.init(document.getElementById('byTime'));
  var byTimeOp = sysBusCountOption.byTimeOp;
  // var titles = $scope.selector.businessName + '业务成交量分时刻统计' + $scope.selector.time;
  var titles = '';
  $scope.searchST = function () {
    if($scope.shoumun.flag === 1){return;}
    sysBusCountServer.byTime(byTimechart,byTimeOp,titles);
  };
}

function byProvinceController($scope,sysBusCountData,sysBusCountOption,sysBusCountServer){
  $scope.shoumun = {flag : 1};
  $scope.selector = sysBusCountData.selector;
  $scope.sendData = sysBusCountData.sendData;
  $scope.isBu = {isBu1:true,isBu2:true,isBu3:true};

  var byProvincechart0 = echarts.init(document.getElementById('byProvince0'));
  var byProvincechart1 = echarts.init(document.getElementById('byProvince1'));
  var byProvincechart2 = echarts.init(document.getElementById('byProvince2'));
  var byProvinceOp0 = sysBusCountOption.byProvinceOp;
  var byProvinceOp1 = sysBusCountOption.byProvinceOp;
  var byProvinceOp2 = sysBusCountOption.byProvinceOp;
  var title0 = '1';var title1 = '2';var title2 = '3';

  $scope.searchST = function () {
    var echartsNum3 = [byProvincechart0,byProvincechart1,byProvincechart2];
    var OpNum3 = [byProvinceOp0,byProvinceOp1,byProvinceOp2];
    var titlesNum3 = [title0,title1,title2];
    if($scope.shoumun.flag === 1){return;}
    if($scope.sendData.displayMode === '总量'){
      $scope.isBu.isBu1 = true;$scope.isBu.isBu2 = false;$scope.isBu.isBu3 = false;
      sysBusCountServer.byProvince(byProvincechart0,byProvinceOp0,title0);
    }else{
      var echartsNum = [];var Ops = []; var titles = [];
      if(!$scope.sendData.chan){
        $scope.isBu.isBu1 = true;$scope.isBu.isBu2 = false;$scope.isBu.isBu3 = false;
      }else if($scope.sendData.chan.length === 1){
        $scope.isBu.isBu1 = true;$scope.isBu.isBu2 = false;$scope.isBu.isBu3 = false;
      }else if($scope.sendData.chan.length === 2){
        $scope.isBu.isBu1 = true;$scope.isBu.isBu2 = true;$scope.isBu.isBu3 = false;
      }else if($scope.sendData.chan.length === 3){
        $scope.isBu.isBu1 = true;$scope.isBu.isBu2 = true;$scope.isBu.isBu3 = true;
      }
      if($scope.sendData.chan){
        for(var i=0;i<$scope.sendData.chan.length;i++){
          echartsNum[i] = echartsNum3[i];
          Ops[i] = OpNum3[i];
          titles[i] = titlesNum3[i];
        }
        sysBusCountServer.byProvince(echartsNum,Ops,titles);
      }
      if(!$scope.sendData.chan  ){
        sysBusCountServer.byProvince(byProvincechart0,byProvinceOp0,title0);
      }
    }

    
  };
}

function successRateController($scope,sysBusCountData,sysBusCountOption,sysBusCountServer){
  $scope.shoumun = {flag : 1};
  $scope.selector = sysBusCountData.selector;
  $scope.sendData = sysBusCountData.sendData;

  var successRatechart = echarts.init(document.getElementById('successRate'));
  var successRateOp = sysBusCountOption.successRateOp;
  var titles = '';

  $scope.searchST = function () {
    if($scope.shoumun.flag === 1){return;}
    sysBusCountServer.successRate(successRatechart,successRateOp,titles);
  };
}

function thirtyController($scope,sysBusCountData,sysBusCountServer,sysBusCountOption){
  $scope.shoumun = {flag : 1};
  $scope.selector = sysBusCountData.selector;
  $scope.sendData = sysBusCountData.sendData;

  var thirtychart = echarts.init(document.getElementById('thirty'));
  var thirtyOp = sysBusCountOption.thirtyOp;
  var titles = '';

  $scope.searchST = function () {
    if($scope.shoumun.flag === 1){return;}
    sysBusCountServer.thirty(thirtychart,thirtyOp,titles);
  };
}

})();